define(["js/ztree/js/jquery.ztree.all-3.5.min","text!html/com/userOrg/userOrg.html"],function(ztree,result) {
	var loadHtml = function(id) {
		var iframeLayoutSet = {
			defaults : {
				size : "auto",
				minSize : 50,
				paneClass : "pane", // default = 'ui-layout-pane'
				resizerClass : "resizer", // default = 'ui-layout-resizer'
				togglerClass : "toggler", // default = 'ui-layout-toggler'
				buttonClass : "button", // default = 'ui-layout-button'
			}
		};
		if (!ich.userOrg) {
			ich.addTemplate("userOrg", result);
		}
		$('#' + id).html(ich.userOrg());
		$('#iframeLayout').layout(iframeLayoutSet);
		orgzTree();
	};
	
	function getUrl() {
		return "../admin/org/getOrgChildrenByPid.json";
	}
	
	var setting = {
			async: {
				enable: true,
				url: getUrl,
				autoParam: ["id","cn"]
			},
			view: {
				selectedMulti: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {  
				onClick: zTreeOnClick,
				onExpand: zTreeOnExpand
			}
		};
		
		
		function zTreeOnExpand(event, treeId, treeNode) {
			if(treeNode && (treeNode.children == "" || treeNode.children == null || typeof(treeNode.children) == "undefined")){
				treeNode.isParent = false;
				var treeObj = $.fn.zTree.getZTreeObj(treeId);
				treeObj.updateNode(treeNode);
			}
			return true;
		};
		
        function zTreeOnClick(event, treeId, treeNode) {
//            alert(treeNode.id + "," + treeNode.name+","+treeNode.pId+","+treeNode.cn);
				if (treeNode.id != undefined && treeNode.id !=""){
					require(["js/com/userOrg/userOrgTable"], function(userOrgTable){
		        		userOrgTable.createTable(treeNode.id);
		        	});
	            }else{
					alert("id为空");
				}
        };
	
	function orgzTree() {
		$.fn.zTree.init($("#orgTree"), setting);
	};
	return {
		loadHtml : loadHtml
	};
});